package com.jiujichaoshi.oauth.server.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.Collections;

/**
 * Description: <p>用途描述</p>
 *
 * @author YangLong [410357434@163.com]
 * @version V1.0 2021/7/16
 */
@EnableSwagger2WebMvc
@Configuration
public class ApiDocConfig {

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        Parameter token = new ParameterBuilder().name("Authorization")
                .description("用户登录后获取的token,必须使用Bearer 开头")
                .required(true)
                .parameterType("header")
                .defaultValue("Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyTmFtZSI6IuWWu-a7lCIsInN1YiI6ImxvZ2luVG9rZW4iLCJpc3MiOiJsZWFwbW90b3JfcG9ydGFsIiwiYXVkIjoiMiIsImlhdCI6MTU2NTY4NDY1NiwiZXhwIjo0NzE5Mjg0NjU2fQ.wJT_7-4xxVPT-twfvIds-EceTrMtJ7ZVJMbHY9FuqhVustnCY-kolooY3YTkX5D0Q6W_JWaIUvayyB9Ka9mXnA")
                .modelRef(new ModelRef("string"))
                .build();
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("swagger-bootstrap-ui-demo RESTful APIs")
                        .description(" Api接口")
                        .termsOfServiceUrl("http://www.leapmotor.com/")
                        .version("1.0")
                        .build())
                .groupName("用户中心")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.jiujichaoshi.oauth.server.controller"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(Collections.singletonList(token));
        return docket;
    }
}
